var $ = require('jquery');

// ques:
// [{
// 	"id": 2595,
// 	"course": 1,
// 	"type": 1,
// 	"mark": 1,
// 	"grade": 3,
// 	"answer": "A",
// 	"question": "采用保险人提供的格式条款订立的保险合同中的条款中无效的有()。",
// 	"sa": "加重投保人、被保险人责任的",
// 	"sb": "规定等待期的",
// 	"sc": "强调投保人、被保险人或者受益人依法享有的权利的",
// 	"sd": "规定免除责任的",
// 	"se": "",
// 	"sf": ""
// },]

// res:
// {
// 	"status": 200,
// 	"message": "登录成功！",
// 	"error": "",
// 	"data": {
// 		"name": "丁琼",
// 		"sessionid": "ff010d6cbe554ad09f40e34607cebe3d"
// 	}
// }

// ques
function getPraQues(sessionid, amount, course) {
	return $.getJSON('/api/practice/questions/', {
		sessionid: sessionid,
		amount: amount,
		course: course
	});
}
// res
function submitPra(sessionid, course, score, doneids = [], errorids = [], rightids = []) {
	doneids = doneids.join(',');
	errorids = errorids.join(',');
	rightids = rightids.join(',');
	return $.post('/api/practice/', {
		sessionid: sessionid,
		score: score,
		course:course,
		doneids: doneids,
		errorids: errorids,
	});
}

// ques
function getTestQues(sessionid, amount, course) {
	return $.getJSON('/api/test/questions/', {
		sessionid: sessionid,
		amount: amount,
		course: course
	});
}
// res
function submitTest(sessionid, course, score, doneids = [], errorids = [], rightids = []) {
	doneids = doneids.join(',');
	errorids = errorids.join(',');
	rightids = rightids.join(',');
	return $.post('/api/test/', {
		sessionid: sessionid,
		score: score,
		course:course,
		doneids: doneids,
		errorids: errorids,
	});
}

// ques
function getErrQues(sessionid, amount, course) {
	return $.getJSON('/api/practice/errors/', {
		sessionid: sessionid,
		amount: amount,
		course: course
	});
}
// resp
function submitErr(sessionid, course, score, doneids = [], errorids = [], rightids = []) {
	doneids = doneids.join(',');
	errorids = errorids.join(',');
	rightids = rightids.join(',');
	return $.post('/api/practice/errors', {
		sessionid: sessionid,
		course:course,
		rightids: rightids,
	});
}
export default {
	getPraQues,
	submitPra,
	getTestQues,
	submitTest,
	getErrQues,
	submitErr,

	test(sessionid) {
		
		getPraQues(sessionid, 10, 1)
			.done(function(data, status){
				console.log('getPraQues,', data);
			});
		submitPra(sessionid, 1, 100, [], [])
			.done(function(data, status){
				console.log('submitPra,', data);
			});
		getTestQues(sessionid, 10, 1)
			.done(function(data, status){
				console.log('getTestQues,', data);
			});
		submitTest(sessionid1, 100, [], [])
			.done(function(data, status){
				console.log('submitTest,', data);
			});
		getErrQues(sessionid, 10, 1)
			.done(function(data, status){
				console.log('getErrQues,', data);
			});
		submitErr(sessionid, 1, [])
			.done(function(data, status){
				console.log('submitErr,', data);
			});
	}
}